package com.net.framework.help.rom;


import com.net.framework.help.utils.LogUtils;

import java.io.IOException;

public class RomUtil {
    private static Target mTarget = null;
    //华为
    private static final String KEY_EMUI_VERSION_CODE = "ro.build.version.emui";
    //小米
    private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
    private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
    private static final String KEY_MIUI_HANDY_MODE_SF = "ro.miui.has_handy_mode_sf";
    private static final String KEY_MIUI_REAL_BLUR = "ro.miui.has_real_blur";
    //魅族
    private static final String KEY_FLYME_ICON = "persist.sys.use.flyme.icon";
    private static final String KEY_FLYME_PUBLISHED = "ro.flyme.published";
    private static final String KEY_FLYME_FLYME = "ro.meizu.setupwizard.flyme";
    //oppo
    private static final String KEY_COLOROS_REGION = "persist.sys.oppo.region";
    private static final String KEY_OPPOROM = "ro.build.version.opporom";
    private static final String KEY_OPPO_DUMP = "persist.sys.oppo.dump";
    //vivo
    private static final String KEY_VIVO_OS = "ro.vivo.os.version";

//    private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
//    private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
//    private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage";
//    private static final String KEY_EMUI_API_LEVEL = "ro.build.hw_emui_api_level";
//    private static final String KEY_EMUI_CONFIG_HW_SYS_VERSION = "ro.confg.hw_systemversion";

    /**
     * Oppo手机Rom
     *
     * @return
     */
    private static boolean isColorOs() {
        try {
            final BuildProperties prop = BuildProperties.newInstance();
            return prop.containsKey(KEY_OPPOROM)
                    || prop.containsKey(KEY_OPPO_DUMP)
                    || prop.containsKey(KEY_COLOROS_REGION);
        } catch (final IOException e) {
            return false;
        }
    }

    /**
     * Vivo手机Rom
     *
     * @return
     */
    private static boolean isViVoOs() {
        try {
            final BuildProperties prop = BuildProperties.newInstance();
            return prop.containsKey(KEY_VIVO_OS);
        } catch (final IOException e) {
            return false;
        }
    }

    /**
     * 华为rom
     *
     * @return
     */
    private static boolean isEMUI() {
        try {
            final BuildProperties prop = BuildProperties.newInstance();
            return prop.containsKey(KEY_EMUI_VERSION_CODE);
        } catch (final IOException e) {
            return false;
        }
    }

    /**
     * 小米rom
     *
     * @return
     */

    private static boolean isMIUI() {
        try {
            final BuildProperties prop = BuildProperties.newInstance();
            return prop.containsKey(KEY_MIUI_VERSION_CODE)
                    || prop.containsKey(KEY_MIUI_VERSION_NAME)
                    || prop.containsKey(KEY_MIUI_REAL_BLUR)
                    || prop.containsKey(KEY_MIUI_HANDY_MODE_SF);
        } catch (final IOException e) {
            return false;
        }
    }

    /**
     * 魅族rom
     *
     * @return
     */
    private static boolean isFlyme() {
        try {
            final BuildProperties prop = BuildProperties.newInstance();
            return prop.containsKey(KEY_FLYME_ICON)
                    || prop.containsKey(KEY_FLYME_PUBLISHED)
                    || prop.containsKey(KEY_FLYME_FLYME);
        } catch (final IOException e) {
            return false;
        }
    }


    public static Target rom() {
        if (null != mTarget) {
            LogUtils.println("直接返回系统类型===" + mTarget);
            return mTarget;
        }
//        if (isEMUI()) {
//            mTarget = Target.EMUI;
//            return mTarget;
//        } else if (isMIUI()) {
//            mTarget = Target.MIUI;
//            return mTarget;
//        } else if (isFlyme()) {
//            mTarget = Target.FLYME;
//            return mTarget;
//        } else if (isColorOs()) {
//            mTarget = Target.COLOROS;
//            return mTarget;
//        } else if (isViVoOs()) {
//            mTarget = Target.FUNTOUCHOS;
//            return mTarget;
//        } else {
//            mTarget = Target.OTHER;
//        }
        mTarget = Target.OTHER;
        return mTarget;
    }
}
